<template>
	<!-- 周例会 -->
	<view class="body">
		<myHeader :title="title"></myHeader>
		<uni-search-bar @confirm="sreachIt()" :focus="false" v-model="search" @clear="clear"></uni-search-bar>
		<!-- 会议记录 -->
		<uni-list v-for="(item,index) in taskList" :key="item.id">
			<uni-list-item :title="item.theme == undefined ? '无标题':item.theme" link="navigateTo"
				@click="pageTo1('./addWeeklyMeetingFile',item)" :note="item.room">
			</uni-list-item>
		</uni-list>

		<!-- 新增 小组长具有该权限-->
		<view v-if="currentRoleCode.includes('fl-group-leader')">
			<uni-fab :pattern="btnPattern" @fabClick="pageTo('./addWeeklyMerting')"></uni-fab>
		</view>
	</view>
</template>

<script>
	import myHeader from '../../components/head.vue'
	import NetWorkTool from '@/api/netWorkTool'
	export default {

		data() {
			return {
				title: '周例会',
				search: '',
				btnPattern: {
					buttonColor: '#e20909'
				},
				taskList: [],
				// 当前用户角色
				currentRoleCode: []
			}
		},
		mounted() {
			this.getLoginUserRoles();
			this.getList()
		},
		methods: {
			// 获取列表
			getList() {
				let param = {
					"current": this.current,
					"pageSize": this.pageSize,
					"param": {
						"theme": this.search
					}
				}
				// 如果是负责人
				if (this.currentRoleCode.includes('fl-leader')) {
					NetWorkTool.POST(`/api/federation-week/getOwnerPage`, param, true).then(res => {
						if (res.records != null || res.records != undefined) {
							this.taskList = res.records
						}
					}).catch(err => {
						uni.showToast({
							title: '暂无信息',
							duration: 2000
						});
					})
				} else {
					NetWorkTool.POST(`/api/federation-week/getPage`, param, true).then(res => {
						if (res.records != null || res.records != undefined) {
							this.taskList = res.records
						}
					}).catch(err => {
						uni.showToast({
							title: '暂无信息',
							duration: 2000
						});
					})
				}

			},
			// 获取登录用户角色
			getLoginUserRoles() {
				let _this = this;
				uni.getStorage({
					key: 'user',
					success(e) {
						let arr = [];
						for (let item of e.data.role) {
							if (null != item.roleCode) {
								_this.currentRoleCode.push(item.roleCode)
							}
						}
					}
				})
			},
			pageTo(val) {
				uni.navigateTo({
					url: val
				})
			},
			pageTo1(val, data) {
				uni.navigateTo({
					url: val + "?data=" + JSON.stringify(data)
				})
			},
			sreachIt() {
				uni.showToast({
					title: this.search,
					duration: 1000
				})
				this.getList();
			},
			clear() {
				this.search = ''
				this.getList()
			}

		},
		components: {
			myHeader
		},
	}
</script>

<style>
</style>
